package com.baizhi.controller.common;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
@RequestMapping("/admin")
public class CaptchaController {

    @RequestMapping("getCaptcha")
    public void getCaptcha(HttpServletResponse response, HttpSession session) throws IOException {
        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20);

        session.setAttribute("code",captcha.getCode());
        System.out.println(captcha.getCode());

        captcha.write(response.getOutputStream());
    }
}
